#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct
{
	char name[20];
	int age;
}Stu;

int struct_cmp_age(const void* e1, const void* e2)
{
	return (((Stu*)e1)->age) - (((Stu*)e2)->age);
}

int struct_cmp_name(const void* e1, const void* e2)
{
	return (strcmp(((Stu*)e1)->name, ((Stu*)e2)->name));
}

int int_cmp(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}

int float_cmp(const void* e1, const void* e2)
{
	return (*(float*)e1) > (*(float*)e2) ? 1 : -1;
}
int main()
{
	int arr[10] = { 1,2,5,4,3,6,7,9,10,8};
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), int_cmp);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	float f[] = { 1.2, 2.4, 4.5, 3.8, 8.3, 2.1, 3.5 };
	int sz2 = sizeof(f) / sizeof(f[0]);
	qsort(f, sz2, sizeof(f[0]), float_cmp);
	for (int i = 0; i < sz2; i++)
	{
		printf("%f ", f[i]);
	}
	printf("\n");
	Stu s[] = { {"zhangsan", 18}, {"lisi", 16}, {"wangwu", 20} };
	int sz3 = sizeof(s) / sizeof(s[0]);
	qsort(s, sz3, sizeof(s[0]), struct_cmp_name);
	qsort(s, sz3, sizeof(s[0]), struct_cmp_age);
	for (int i = 0; i < sz3; i++)
	{
		printf("%d ", s[i].age);
	}
	printf("\n");
	Stu* ps = &s;
	printf("%s", ps->name);
	printf("%s", (ps + 1)->name);
	printf("%s", (ps + 2)->name);
	return 0;
}